package cn.fiker.BeautyPic.worker;

import java.util.Iterator;
import java.util.List;

import cn.fiker.BeautyPic.Log;

import android.content.Context;

/**
 * 检测运行任务
 * 
 * @author liuqs
 * 
 */
public class TaskRunningCheck {

	private Context context;
	private List<Program> runningList;
	private Program runningProgram;

	public TaskRunningCheck(Context context) {
		this.context = context;
	}

	/**
	 * 检测正在运行的所有应用包名
	 */
	public void checkRunningProcess() {
		runningList = getRunningProcess();
		if (runningList == null) {
			return;
		}

		Iterator<Program> iterator = runningList.iterator();
		while (iterator.hasNext()) {
			runningProgram = iterator.next();
			Log.i("TaskRunningCheck",
					"running ==> " + runningProgram.getPackageName() + "  "
							+ runningProgram.getName());
		}
	}

	/**
	 * 返回所有正在运行的应用
	 * 
	 * @return
	 */
	public List<Program> getRunningProcess() {
		PackagesInfo packageInfo = new PackagesInfo(this.context);
		runningList = packageInfo.getRunningProcess();
		return runningList;
	}
}
